package org.example.kafka.admin;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.NewTopic;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author : 叶荻风
 * @create : 2024/6/17 10:31
 */
public class AdminTopicTest {
    public static void main(String[] args) {
        Map<String,Object> configMap = new HashMap<>();
        //kafka端口
        configMap.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,"localhost:9092");
        //管理员对象
        Admin admin = Admin.create(configMap);

        String topicName = "test3";
        int partitionNumber = 2; //2个分区
        short replicaNumber = 2; //2个副本
        NewTopic topic1 = new NewTopic(topicName,partitionNumber,replicaNumber);
        admin.createTopics(Arrays.asList(topic1));
        admin.close();
    }
}
